3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
6 Slow. Takes ~14 seconds on 100 hundred strings of length 1000.
29 #define D(x) cout << #x " is " << x << endl
31 inline int v(char c
){if(c
=='A')return 0;if(c
=='C')return 1;if(c
=='G')return 2;if(c
=='T')return 3;};
36 node(int i
= 0) : info(i
){ sons
[0] = sons
[1] = sons
[2] = sons
[3] = NULL
; }
39 void clean(node
* &u
){
41 for (int i
=0; i
<4; ++i
) clean(u
->sons
[i
]);
48 //freopen("gattaca.in", "r", stdin);
54 int n
= s
.size(), rep
= 0;
57 node
* root
= new node
;
59 for (int i
=0; i
<n
; ++i
){
60 node
* foot
= root
; //Tells me where i'm standing.
63 for (int j
=i
; j
< n
; ++j
){
64 so_far
= s
.substr(i
, j
-i
+1);
65 if (foot
->sons
[v(s
[j
])] == NULL
) foot
->sons
[v(s
[j
])] = new node
;
66 foot
= foot
->sons
[v(s
[j
])];
68 if (t
> 1 && (so_far
.size() > ans
.size() || (so_far
.size() == ans
.size() && so_far
< ans
))){
74 if (rep
== 0) cout
<< "No repetitions found!\n";
75 else cout
<< ans
<< " " << rep
<< endl
;